// 要将loading注册为全局组件
import Vue from 'vue'
import MyLoading from '@/components/MyLoading/MyLoading'
// Vue.component
const CreateLoading = Vue.extend(MyLoading)
// console.log(CreateLoading);
// 实例化组件 将该组件的挂载点设置为一个自己创建的div

const instence = new CreateLoading({
    el: document.createElement('div')
})
// console.log(instence);
// instence 是一个实例化对象 给当前实例添加一个自定义属性
instence.show = false

const $loading = {
    show(msg) {
        instence.show = true
        instence.msg = msg
        document.body.appendChild(instence.$el) // $el 其实就是挂载点的dom 
    },

    hide() {
        instence.show = false
    }
}

export default {
    // install 必须写成install 因为 Vue.use() 会调用install
    install() {
        if(!Vue.$loading) {
            Vue.$loading = $loading
        }

        Vue.mixin({
            created() {
                this.$loading = Vue.$loading
            }
        })
    }
}